package com.zxyankh.generator.math.practice.impl;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

import com.zxyankh.generator.math.practice.ProblemOutput;
import com.zxyankh.generator.math.practice.dto.Problem;

public class TxtProblemOutput implements ProblemOutput {

	private final String LINE_SEPARATOR = System.lineSeparator();
	private String path = System.getProperty("user.dir");

	public void output(List<Problem> problemList) {
		StringBuilder stringBuilder = new StringBuilder();
		for (Problem p : problemList) {
			stringBuilder.append(p.toQuestion()).append(LINE_SEPARATOR);
		}
		for (int i = 0; i < 10; i++) {
			stringBuilder.append(LINE_SEPARATOR);
		}
		for (Problem p : problemList) {
			stringBuilder.append(p.toAnswer()).append(LINE_SEPARATOR);
		}
		File targetFile = new File(path,"question.txt");
		try {
			Files.write(targetFile.toPath(), stringBuilder.toString().getBytes());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
